package kr.saeildamil.androidstudy.ch16;

import kr.saeildamil.androidstudy.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class OrderDialog extends Activity {
	LinearLayout layout;

	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch16_orderdialog);
	}

	public void mOnClick(View v) {
		layout = (LinearLayout) View.inflate(this, R.layout.ch16_order, null);

		new AlertDialog.Builder(this).setTitle("주문정보를 입력하세요")
				.setIcon(R.drawable.iu).setView(layout)
				.setPositiveButton("확인", listener)
				.setNegativeButton("취소", listener).show();
	}

	DialogInterface.OnClickListener listener = new OnClickListener() {
		public void onClick(DialogInterface dialog, int which) {
			TextView result = (TextView) findViewById(R.id.ch16_orderdialog_tv);
			switch (which) {
			case DialogInterface.BUTTON_POSITIVE:
				EditText product = (EditText) layout
						.findViewById(R.id.ch16_order_product);
				EditText number = (EditText) layout
						.findViewById(R.id.ch16_order_number);
				CheckBox paymethod = (CheckBox) layout
						.findViewById(R.id.ch16_order_paymethod);
				result.setText("★주문정보 ---------------------------★ \n - 상품명 : " + product.getText()
						+ "\n - 갯수 : " + number.getText() + "\n"
						+ (paymethod.isChecked() ? " - 택배비 : 착불" : " - 택배비 : 선불")
						+ "\n --------------------------------");

				break;
			case DialogInterface.BUTTON_NEGATIVE:
				TextView tv = (TextView) findViewById(R.id.ch16_orderdialog_tv);
				tv.setText("주문을 취소합니다");
				break;
			}

		}
	};
}
